home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue55 / Persist / MidReg2.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2000-02-02  |  3.8 KB  |  139 lines

  1. unit MidReg2;
  2. {
  3. Author     : Guy Smith-Ferrier
  4. Date       : February 2000
  5. Description:
  6. This unit is a block copy of the TClientDataSetEditor and TCDSDesigner
  7. classes in Delphi 5's own MidReg.PAS. There have been no changes to this code
  8. whatsoever. The reason for creating this new unit is simply to change the
  9. scope of the classes so that they are in the interface section instead of
  10. in the implementation section. This allows the classes to be inherited from.
  11. }
  12.  
  13. interface
  14.  
  15. uses
  16.   DSDesign, DsgnIntf, DBReg;
  17.  
  18. type
  19.   TClientDataSetEditor = class(TDataSetEditor)
  20.   private
  21.     FCanCreate: Boolean;
  22.   protected
  23.     function GetDSDesignerClass: TDSDesignerClass; override;
  24.   public
  25.     procedure ExecuteVerb(Index: Integer); override;
  26.     function GetVerb(Index: Integer): string; override;
  27.     function GetVerbCount: Integer; override;
  28.   end;
  29.  
  30.   TCDSDesigner = class(TDSDesigner)
  31.   private
  32.     FPacketRecords: Integer;
  33.   public
  34.     procedure BeginUpdateFieldDefs; override;
  35.     procedure EndUpdateFieldDefs; override;
  36.     function SupportsAggregates: Boolean; override;
  37.     function SupportsInternalCalc: Boolean; override;
  38.   end;
  39.  
  40. implementation
  41.  
  42. uses
  43.   DBClient, CDSEdit, DsnDBCst;
  44.  
  45. procedure TCDSDesigner.BeginUpdateFieldDefs;
  46. begin
  47.   FPacketRecords := 0;
  48.   if not DataSet.Active then
  49.   begin
  50.     DataSet.FieldDefs.Updated := False;
  51.     FPacketRecords := (DataSet as TClientDataSet).PacketRecords;
  52.     if FPacketRecords <> 0 then
  53.       (DataSet as TClientDataSet).PacketRecords := 0;
  54.   end;
  55.   inherited BeginUpdateFieldDefs;
  56. end;
  57.  
  58. procedure TCDSDesigner.EndUpdateFieldDefs;
  59. begin
  60.   inherited EndUpdateFieldDefs;
  61.   if FPacketRecords <> 0 then
  62.     (DataSet as TClientDataSet).PacketRecords := FPacketRecords;
  63. end;
  64.  
  65. function TCDSDesigner.SupportsAggregates: Boolean;
  66. begin
  67.   Result := True;
  68. end;
  69.  
  70. function TCDSDesigner.SupportsInternalCalc: Boolean;
  71. begin
  72.   Result := True;
  73. end;
  74.  
  75. function TClientDataSetEditor.GetDSDesignerClass: TDSDesignerClass;
  76. begin
  77.   Result := TCDSDesigner;
  78. end;
  79.  
  80. procedure TClientDataSetEditor.ExecuteVerb(Index: Integer);
  81. begin
  82.   if Index <= inherited GetVerbCount - 1 then
  83.     inherited ExecuteVerb(Index) else
  84.   begin
  85.     Dec(Index, inherited GetVerbCount);
  86.     if (Index > 2) and not FCanCreate then Inc(Index);
  87.     case Index of
  88.       0: begin
  89.            TClientDataSet(Component).FetchParams;
  90.            Designer.Modified;
  91.          end;
  92.       1: if EditClientDataSet(TClientDataSet(Component), Designer) then
  93.            Designer.Modified;
  94.       2: if LoadFromFile(TClientDataSet(Component)) then Designer.Modified;
  95.       3: begin
  96.            TClientDataSet(Component).CreateDataSet;
  97.            Designer.Modified;
  98.          end;
  99.       4: SaveToFile(TClientDataSet(Component));
  100.       5: begin
  101.            TClientDataSet(Component).Data := NULL;
  102.            Designer.Modified;
  103.          end;
  104.     end;
  105.   end;
  106. end;
  107.  
  108. function TClientDataSetEditor.GetVerb(Index: Integer): string;
  109. begin
  110.   if Index <= inherited GetVerbCount - 1 then
  111.     Result := inherited GetVerb(Index) else
  112.   begin
  113.     Dec(Index, inherited GetVerbCount);
  114.     if (Index > 2) and not FCanCreate then Inc(Index);
  115.     case Index of
  116.       0: Result := SFetchParams;
  117.       1: Result := SClientDSAssignData;
  118.       2: Result := SLoadFromFile;
  119.       3: Result := SCreateDataSet;
  120.       4: Result := SSaveToFile;
  121.       5: Result := SClientDSClearData;
  122.     end;
  123.   end;
  124. end;
  125.  
  126. function TClientDataSetEditor.GetVerbCount: Integer;
  127. begin
  128.   Result := inherited GetVerbCount + 3;
  129.   FCanCreate := False;
  130.   with TClientDataset(Component) do
  131.   begin
  132.     if Active or (DataSize > 0) then Inc(Result, 2);
  133.     FCanCreate := not Active and ((FieldCount > 0) or (FieldDefs.Count > 0));
  134.     if FCanCreate then Inc(Result, 1);
  135.   end;
  136. end;
  137.  
  138. end.
  139.